package com.ck.ips.controller;

import com.ck.common.model.File;
import com.ck.common.model.OperationResult;
import com.ck.core.annotation.LoginRequired;
import com.ck.core.util.HuaWeiCloudUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
* @Description: 上传文件组件
* @Author: hf
* @Date:    2019/5/8 11:09
* @Version: 1.0
*/
@LoginRequired
@RestController
public class UploadController extends BaseController{
	private static Logger logger = LoggerFactory.getLogger(UploadController.class);
	private static final String DEFAULT_FILE_SAVE_PATH = "common";

	@RequestMapping(value = "/uploadfile")
	public OperationResult getStoreList(MultipartFile files) {
		try {
			String url = HuaWeiCloudUtils.uploadFile2HuaweiCloud(files, DEFAULT_FILE_SAVE_PATH);
			List<File> successFiles = new ArrayList<>();
			successFiles.add(new File(url));
			return OperationResult.newSuccessOperationResult(successFiles);
		} catch (Exception e) {
			logger.error( e.getMessage() + "上传文件到OBS异常",e);
			return OperationResult.newSystemErrorOperationResult();
		}
	}

}
